package cn.uway.controller.demo;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.uway.pojo.demo.UserInfo;
import cn.uway.service.demo.DemoService;


@RestController
@RequestMapping("/user")
public class DemoController {   
	
	@Autowired
	private DemoService demoService;     
       
    @RequestMapping(value ="/loginCheck" , method=RequestMethod.POST )
    public Map<String,Object> loginCheck(HttpServletRequest request, HttpServletResponse response) {
    	String loginName = request.getParameter("username");
    	String password = request.getParameter("password");
    	Map<String,Object> resultMap = demoService.loginCheck(loginName, password);
        return resultMap;
    }
    
    
    @RequestMapping(value ="/getUserInfo" /*, method=RequestMethod.POST */)
    public UserInfo getUserInfo(HttpServletRequest request, HttpServletResponse response, String userId) {
    	UserInfo user = demoService.findUserById(userId);
    	System.out.println("=============user="+user);    	
    	if(user==null){
    		user = new UserInfo();
            user.setUserName("默认用户：张三丰");
            user.setLoginName("default");
            user.setPassword("BC69AE4A66EF117E38B5F047B8B2A3B9");
            user.setUserId(userId);
            
    	}    	
        return user;
    }
}
